<%--
  Created by IntelliJ IDEA.
  User: wesley.wei
  Date: 2018-06-01
  Time: 13:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>layout 后台大布局 - Layui</title>
    <link rel="stylesheet" href="/componments/layui/css/layui.css">
    <style>
        .grid-demo-bg1 {
            background-color: #63BA79;
        }
        .grid-demo {
            background-color: #63BA78;
        }
    </style>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">

    <%@include file="../common/header.jsp"%>

    <%@include file="../common/left.jsp"%>

    <div class="layui-body">
        <!-- 内容主体区域 -->

        <div style="padding: 15px;">


            <form class="layui-form" action="">
                <div class="layui-form-item">
                    <label class="layui-form-label">标题</label>
                    <div class="layui-input-inline">
                        <input id="title" type="text" name="title" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">内容</label>
                    <div class="layui-input-block" style="">
                        <div style="width: 450px;height: 450px;">
                        <script id="container" name="content" type="text/plain"></script>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block" style="margin-top: 72px">
                        <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>

        </div>

    </div>

    <%@include file="../common/footer.jsp"%>

</div>

<script src="/componments/jquery/jquery-3.1.1.min.js"></script>
<script src="/componments/ueditor/ueditor.config.js"></script>
<script src="/componments/ueditor/ueditor.all.js"></script>
<script src="/componments/ueditor/ueditor.parse.js"></script>
<script src="/componments/layui/layui.js"></script>

<script>
    var ue = UE.getEditor('container',{
        initialFrameHeight:400,
        initialFrameWidth:900,
        toolbars: [[
            'undo', //撤销
            'redo', //重做
            'bold', //加粗
            'italic', //斜体
            'underline', //下划线
            'strikethrough', //删除线
            'forecolor', //字体颜色
            'justifyleft', //居左对齐
            'justifyright', //居右对齐
            'justifycenter', //居中对齐
            'justifyjustify', //两端对齐
            'inserttable', //插入表格
            'simpleupload', //多图上传
            'backcolor', //背景色
            'fontfamily', //字体
            'fontsize', //字号
            'insertvideo',
            'paragraph', //段落格式
            'insertorderedlist', //有序列表
            'insertunorderedlist', //无序列表
            'lineheight', //行间距
        ]
        ]
    });
    UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;

    //上传
    UE.Editor.prototype.getActionUrl = function(action) {
        if (action == 'uploadimage') {
            //上传图片
            return '/common/upload/image';
        } else if (action == 'uploadvideo'){
            //上传视频
            return '/common/upload/video';
        }else {
            return this._bkGetActionUrl.call(this, action);
        }
    }

    var table = undefined;
    var form = undefined;
    layui.use(['element','table','form'], function(){
        table = layui.table;
        form = layui.form;

        form.on('submit(formDemo)', function(data){

            var content = ue.getContent();
            console.log(content)

            var title = $('#title').val();


            var index = layer.load();
            $.ajax({
                type:'get',
                url : '/topic/save',
                data:{
                    content : content,
                    title: title
                },
                dataType:'json',
                success:function (data) {
                    layer.close(index);
                    if(data.tag){
                        layer.alert("保存成功")
                    } else {
                        layer.alert("保存失败")
                    }
                },
                error:function (data) {
                    layer.close(index);
                    layer.alert("网络错误")
                    return;
                }
            });
            return false;
        });

    });


</script>
</body>
</html>
